package cn.edu.stu.syllabus.repository.banner;

import java.util.ArrayList;
import java.util.List;

import cn.edu.stu.syllabus.repository.banner.local.BannerEntry;
import cn.edu.stu.syllabus.repository.banner.local.BannerInfoEntry;
import cn.edu.stu.syllabus.repository.banner.remote.Banner;
import cn.edu.stu.syllabus.repository.banner.remote.BannerInfo;
import cn.edu.stu.syllabus.repository.banner.remote.BannerList;

/**
 * Created by daidaijie on 2017/3/13.
 */

public class BannerConverter {

    public static BannerInfoEntry convert(BannerInfo bannerInfo) {
        BannerInfoEntry bannerInfoEntry = new BannerInfoEntry();
        List<BannerEntry> bannerEntries = new ArrayList<>();

        BannerList bannerList = bannerInfo.getBannerList();
        for (Banner banner : bannerList.getBanners()) {
            bannerEntries.add(convert(banner));
        }

        bannerInfoEntry.setTimestamp(bannerInfo.getBannerList().getTimestamp());
        bannerInfoEntry.setBannerEntries(bannerEntries);

        return bannerInfoEntry;
    }

    private static BannerEntry convert(Banner banner) {
        BannerEntry bannerEntry = new BannerEntry();
        bannerEntry.setId(banner.getId());
        bannerEntry.setDesc(banner.getDescription());
        bannerEntry.setImgUrl(banner.getUrl());
        bannerEntry.setLink(banner.getLink());

        return bannerEntry;
    }
}
